package com.ww7h.mvvm

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelStoreOwner

/**
 * ================================================
 * 描述：
 * 来源：     Android Studio.
 * 项目名：   bo-an-poj-common
 * 包名：     com.ww7h.bigobj
 * 创建时间：  2020/11/26 02:08
 * @author   ww
 * ================================================
 */
interface ViewCommon {

    fun <VM : ViewModel?> getViewModel(
        viewModelStoreOwner: ViewModelStoreOwner,
        tClass: Class<VM>
    ): VM {
        return ViewModelProvider(viewModelStoreOwner)[tClass]
    }

    fun <VDB : ViewDataBinding> getViewDataBinding(
        inflater: LayoutInflater,
        viewGroup: ViewGroup?,
        layoutId: Int
    ): VDB {
        return DataBindingUtil.inflate(
            inflater,
            layoutId,
            viewGroup,
            false
        )
    }
}